<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="部门" prop="dwName">
              <el-input v-model="queryParams.dwName" placeholder="请输入部门" clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="岗位" prop="userName">
              <el-select v-model="queryParams.userName" style="width: 200px;" clearable placeholder="请选择岗位">
                  <el-option
                      v-for="item in swList"
                      :key="item.value"
                      :label="item.label"
                      :value="Number(item.value)"
                  ></el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="员工" prop="xsBd">
              <el-input v-model="queryParams.xsBd" placeholder="请输入员工" clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="提交时间" prop="dateRange">
              <el-date-picker
              v-model="queryParams.dateRange"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00','23:59:59']"
              ></el-date-picker>
          </el-form-item>
          <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
      </el-form>

      <TableCard>
          <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                  <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" >
                      新增
                  </el-button>
              </el-col>
              <el-col :span="1.5">
                  <el-button type="info" plain icon="el-icon-upload2" size="mini" >导入</el-button>
              </el-col>
              <el-col :span="1.5">
                  <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" >
                      导出
                  </el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table :border="Global.tableShowBorder" v-loading="loading" :data="communicateBookList">
              <el-table-column v-for="(item,index) in tableList" :key="index" :label="item.label" align="center" :prop="item.prop" :width="item.width || ''">
                  <template slot-scope="{row}">
                      {{row[item.prop]}}
                  </template>
              </el-table-column>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160px">
                  <template slot-scope="scope">
                      <el-button size="mini" type="text" icon="el-icon-view" @click="handleUpdate(scope.row)" >
                        查看
                      </el-button>
                      <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">
                        删除
                      </el-button>
                  </template>
              </el-table-column>
          </el-table>

          <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
      </TableCard>

      <!-- 添加或修改个人通讯录对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
              <el-row>
                  <el-col :span="12" v-for="(item,index) in tableList" :key="index">
                      <el-form-item :label="item.label" :prop="item.prop">
                          <el-input v-model="form[item.prop]" :placeholder="`请输入${item.label}`"/>
                      </el-form-item>
                  </el-col>
              </el-row>

          </el-form>
          <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="submitForm">确 定</el-button>
              <el-button @click="cancel">取 消</el-button>
          </div>
      </el-dialog>
  </div>
</template>

<script>
import {
  listCommunicateBook,
  getCommunicateBook,
  delCommunicateBook,
  addCommunicateBook,
  updateCommunicateBook
} from "@/api/common/communicateBook";

export default {
  name: "custoManag",
  data() {
      return {
          swList:[
            {label:'张祁阳',value:1,},{label:'王俊豪',value:4,},{label:'张军和',value:4,},
            {label:'王少奇',value:2,},{label:'黄杜娟',value:3,},
          ],
          tableList:[
            {label:'员工姓名',prop:'yuangong',width:'160px',},{label:'所在部门',prop:'bumen',width:'160px',},{label:'岗位',prop:'gangwei',width:'160px',},
            {label:'参保地',prop:'address',width:'160px',},{label:'薪资归属月份',prop:'month',width:'160px',},{label:'薪资归属年份',prop:'year',width:'160px',},
            {label:'上月月份',prop:'lastMonth',width:'160px',},{label:'基本工资',prop:'jbgz',width:'160px',},{label:'绩效薪资',prop:'jxxz',width:'160px',},
            {label:'补贴',prop:'butie',width:'160px',},{label:'绩效系数',prop:'jxxs',width:'160px',},{label:'当月绩效薪资',prop:'dyjxxz',width:'160px',},
            {label:'当月税前加减项',prop:'dysqjjx',width:'160px',},{label:'当月工资薪金所得',prop:'dygzxzsd',width:'160px',},{label:'公积金基数确认',prop:'gjjjsqr',width:'160px',},
            {label:'社保基数确认',prop:'sbjsqr',width:'160px',},{label:'企业缴纳养老',prop:'qyjnylao',width:'160px',},{label:'企业缴纳医疗',prop:'qyjnyl',width:'160px',},
            {label:'企业缴纳失业',prop:'qyjnsy',width:'160px',},{label:'企业缴纳工伤',prop:'qyjngs',width:'160px',},{label:'企业缴纳生育',prop:'qyjnsyu',width:'160px',},
            {label:'个人缴纳养老',prop:'grjnyl',width:'160px',},{label:'个人缴纳医疗',prop:'grjnylliao',width:'160px',},{label:'个人缴纳失业',prop:'grjnsle',width:'160px',},
            {label:'个人缴纳工伤',prop:'grjngs',width:'160px',},{label:'个人缴纳生育',prop:'grjnssy',width:'160px',},
            {label:'当月应纳税所得额',prop:'dyyssde',width:'160px',},{label:'上月累计缴纳个税',prop:'syljjngs',width:'160px',},{label:'上月累计缴纳社保',prop:'sylgjnsb',width:'160px',},
            {label:'上月累计缴纳公积金',prop:'syljgjj',width:'160px',},{label:'上月累计专项附加扣除',prop:'syljfjkc',width:'160px',},{label:'上月累计应纳税所得额',prop:'syljsds',width:'160px',},
            {label:'当月累计应纳税所得额',prop:'syljjnsde',width:'160px',},{label:'当月应缴纳个税',prop:'dyjngs',width:'160px',},
            {label:'税率',prop:'syshuilv',width:'160px',},{label:'速算扣除数',prop:'sskcs',width:'160px',},{label:'当月实发',prop:'dysf',width:'160px',},
            {label:'提交人',prop:'name',width:'160px',},{label:'提交时间',prop:'createTime',width:'160px',},{label:'更新时间',prop:'updateTime',width:'160px',},
          ],
          baseUrl: process.env.VUE_APP_BASE_API,
          // 遮罩层
          loading: true,
          // 选中数组
          ids: [],
          // 非单个禁用
          single: true,
          // 非多个禁用
          multiple: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 个人通讯录表格数据
          communicateBookList: [],
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
          // 查询参数
          queryParams: {
              pageNum: 1,
              pageSize: 20,
              orderByColumn: "createTime",
              isAsc: "descending",
              userId: null,
              avatar: null,
              name: null,
              birthDate: null,
              idNum: null,
              phone: null,
              email: null,
              companyName: null,
              companyAddress: null,
              address: null
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
              name: [
                  {required: true, message: "姓名不能为空", trigger: "blur"}
              ],
          }
      };
  },
  created() {
      this.getList();
  },
  methods: {
      /** 查询个人通讯录列表 */
      getList() {
          this.communicateBookList = [
              {
                month:'202501',year:'2025',yuangong:'张祁阳',bumen:'福建行无忧智能科技有限公司',gangwei:'品牌营销',
                address:'杭州市',lastMonth:'202412',dyjxxz:'3000',butie:'500',dysqjjx:'2080', dygzxzsd:'9800',dyyssde:'4900',jbgz:'8900',jxxz:'1200',
                jxxs:'0.8',syljsds:'6541',sylgjnsb:'3150',syljgjj:'2400',syljfjkc:'3000', syljjngs:'675.3',syljjnsde:'4900',syshuilv:'0.03',sskcs:'0',
                dyjngs:'339.15',dysf:'6541',gjjjsqr:'8000',sbjsqr:'9000',qyjnylao:'2,520',qyjnyl:'2,070',qyjnsy:'180',qyjngs:'180',qyjnsyu:'180',
                grjnyl:'1,440',grjnylliao:'360',grjnsle:'90',grjngs:'0',grjnssy:'0',
                name:'张祁阳',createTime:'2025-08-01 11:53:00',updateTime:'2023-08-02 11:53:00',
              },
              {
                month:'202503',year:'2025',yuangong:'黄杜娟',bumen:'福建行无忧智能科技有限公司',gangwei:'华南销售',
                address:'杭州市',lastMonth:'202502',dyjxxz:'3000',butie:'500',dysqjjx:'2080', dygzxzsd:'9800',dyyssde:'4900',jbgz:'7600',jxxz:'1200',
                jxxs:'0.8',syljsds:'1456',sylgjnsb:'4725',syljgjj:'2400',syljfjkc:'3000', syljjngs:'675.3',syljjnsde:'4900',syshuilv:'0.10',sskcs:'0',
                dyjngs:'935.55',dysf:'6541',gjjjsqr:'8100',sbjsqr:'9200',qyjnylao:'2,120',qyjnyl:'1,725',qyjnsy:'150',qyjngs:'150',qyjnsyu:'150',
                grjnyl:'1,200',grjnylliao:'300',grjnsle:'75',grjngs:'0',grjnssy:'0',
                name:'黄杜娟',createTime:'2025-08-01 11:53:00',updateTime:'2023-08-02 11:55:00',
              },
              {
                month:'202504',year:'2025',yuangong:'王俊豪',bumen:'福建行无忧智能科技有限公司',gangwei:'产品经理',
                address:'杭州市',lastMonth:'202503',dyjxxz:'3000',butie:'500',dysqjjx:'2080', dygzxzsd:'9800',dyyssde:'4900',jbgz:'8500',jxxz:'1200',
                jxxs:'0.8',syljsds:'4514',sylgjnsb:'4725',syljgjj:'3600',syljfjkc:'4500', syljjngs:'996.45',syljjnsde:'4900',syshuilv:'0.03',sskcs:'2520',
                dyjngs:'327.15',dysf:'6541',gjjjsqr:'8400',sbjsqr:'9100',qyjnylao:'2,220',qyjnyl:'2,070',qyjnsy:'180',qyjngs:'180',qyjnsyu:'180',
                grjnyl:'1,440',grjnylliao:'360',grjnsle:'90',grjngs:'0',grjnssy:'0',
                name:'王俊豪',createTime:'2025-08-01 11:53:00',updateTime:'2023-08-02 11:50:00',
              },
              {
                month:'202502',year:'2025',yuangong:'张军和',bumen:'福建行无忧智能科技有限公司',gangwei:'后端研发',
                address:'杭州市',lastMonth:'202501',dyjxxz:'3000',butie:'500',dysqjjx:'2080', dygzxzsd:'9800',dyyssde:'4900',jbgz:'6300',jxxz:'1200',
                jxxs:'0.8',syljsds:'9521',sylgjnsb:'1575',syljgjj:'3600',syljfjkc:'4500', syljjngs:'996.45',syljjnsde:'4900',syshuilv:'0.03',sskcs:'0',
                dyjngs:'330.15',dysf:'6541',gjjjsqr:'8300',sbjsqr:'9500',qyjnylao:'2,620',qyjnyl:'2,070',qyjnsy:'180',qyjngs:'180',qyjnsyu:'180',
                grjnyl:'1,440',grjnylliao:'360',grjnsle:'90',grjngs:'0',grjnssy:'0',
                name:'张军和',createTime:'2025-08-01 11:53:00',updateTime:'2023-08-02 11:47:00',
              },
              {
                month:'202503',year:'2025',yuangong:'王少奇',bumen:'福建行无忧智能科技有限公司',gangwei:'后端研发',
                address:'杭州市',lastMonth:'202502',dyjxxz:'3000',butie:'500',dysqjjx:'2080', dygzxzsd:'9800',dyyssde:'4900',jbgz:'9800',jxxz:'1200',
                jxxs:'0.8',syljsds:'3654',sylgjnsb:'1575',syljgjj:'1200',syljfjkc:'1500', syljjngs:'327.15',syljjnsde:'4900',syshuilv:'0.03',sskcs:'0',
                dyjngs:'330.15',dysf:'6541',gjjjsqr:'8200',sbjsqr:'9600',qyjnylao:'2,820',qyjnyl:'1,840',qyjnsy:'160',qyjngs:'160',qyjnsyu:'160',
                grjnyl:'1,280',grjnylliao:'320',grjnsle:'80',grjngs:'0',grjnssy:'0',
                name:'王少奇',createTime:'2025-08-01 11:53:00',updateTime:'2023-08-02 11:44:00',
              },
          ]
          this.loading = false
      },
      // 取消按钮
      cancel() {
          this.open = false;
          this.reset();
      },
      // 表单重置
      reset() {
          this.form = {
              id: null,
              userId: null,
              avatar: null,
              name: null,
              birthDate: null,
              idNum: null,
              phone: null,
              email: null,
              remark: null,
              companyName: null,
              companyAddress: null,
              updateTime: null,
              createTime: null,
              address: null
          };
          this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
          this.ids = selection.map(item => item.id)
          this.single = selection.length !== 1
          this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
          this.reset();
          this.open = true;
          this.title = "添加客户单位管理";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
          this.reset();
          this.form = {...row}
          this.open = true;
          this.title = "修改客户单位管理";
      },
      /** 提交按钮 */
      submitForm() {
          this.$refs["form"].validate(valid => {
              if (valid) {
                  if (this.form.id != null) {
                      updateCommunicateBook(this.form).then(response => {
                          this.$modal.msgSuccess("修改成功");
                          this.open = false;
                          this.getList();
                      });
                  } else {
                      addCommunicateBook(this.form).then(response => {
                          this.$modal.msgSuccess("新增成功");
                          this.open = false;
                          this.getList();
                      });
                  }
              }
          });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
          const ids = row.id || this.ids;
          this.$modal.confirm('是否确认删除该数据项？').then(function () {
              return delCommunicateBook(ids);
          }).then(() => {
              this.getList();
              this.$modal.msgSuccess("删除成功");
          }).catch(() => {
          });
      },
      /** 导出按钮操作 */
      handleExport() {
          this.download('oa/communicateBook/export', {
              ...this.queryParams
          }, `communicateBook_${new Date().getTime()}.xlsx`)
      }
  }
};
</script>
